Repository navigation
Conversation
|
I have read the CLA Document and I hereby sign the CLA |
|
Two additions: a picture of the case, and a second possible fix that I measured against this one. The real table. It is from a public court ruling, a PDF written by Microsoft Word 2016. Red boxes are the blanks Word pads the cell with, blue boxes are the glyphs, both as The bug is older than 2.1. Same repro as in #5327:
So The other fix:
Both give the same result on everything I have. I kept the PR in |
ilgeunben
left a comment
There was a problem hiding this comment.
Thanks — automated signature comparison of the changed source files with the docs (source parsed, not executed) (no AI).
Introduced by this PR:
- `` –
WordExtractor: new public class `WordExtractor` (1 methods: blank_under_glyphs) is not documented
Suggested docs change:docs/<new page>.rst (and add it to a toctree) .. class:: WordExtractor() * New in v<next> .. method:: blank_under_glyphs(chars, i) :arg chars: TODO :arg i: TODO * New in v<next>
) Word processors pad table cells with runs of spaces, and such a run can reach under the text of the cell. Since 2.1 the line-based finder builds its chars without TEXT_ACCURATE_BBOXES when layout is off, so these blanks are in the char list. WordExtractor orders the chars of a line by where they start and ends a word at every blank, so a blank lying under the first digit of "600.000" ended the word after that digit and Table.extract() returned "6 00.000". With the run under the whole number it returned "6 0 0 . 0 0 0". WordExtractor now skips a blank when the glyphs next to it cover more than half of its extent along the line. The gap between the glyphs then decides about the word break, as it did when blanks were not in the list. An ordinary word space lies between its neighbours and is not affected.
|
Thanks for the check. To leave no public name behind, I renamed it to |
80a335b to
8abcd2c
Compare
|
A note on the red CLA check, since it is not specific to this PR: the The run page gives the reason (run 47075738997, Annotations):
|

Fixes #5327.
Table.extract()returns6 00.000for a cell holding600.000when the cell is padded with spaces and the last space of the run lies under the first digit. With the run under the whole number it returns6 0 0 . 0 0 0.Cause. Since 47e52ae (2.1) the line-based finder builds its chars without
TEXT_ACCURATE_BBOXESwhen layout is off, so blanks are in the char list.WordExtractororders the chars of a line by where they start and ends a word at every blank. A blank lying under a glyph is ordered after that glyph, so the word ends there.Fix.
WordExtractor.iter_chars_to_words()skips a blank when the glyphs next to it (the nearest one before it and those that reach into it after it) cover more than half of its extent along the line. The gap between the glyphs then decides about the word break throughchar_begins_new_word(), as it did when blanks were not in the list. An ordinary word space lies between its neighbours, is covered by neither and still ends the word. The check followschar_begins_new_word()for non-upright chars.Tests.
test_5327()builds the page in memory and covers three placements: the run ending under the first digit, the run under the whole number, and a blank between two words drawn as separate spans. It usesfind_tables(use_layout=False); with layout on, the layout model finds no table on that small page.table.py:tests/test_tables.py58 passed (PYMUPDF_TEST_USE_LAYOUT=0). On the unpatched filetest_5327fails with['Pillows', '6 00.000'].test_5327passes with and without the change, since blanks are not in the char list there.